package com.watch.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.watch.system.common.result.PageResult;
import com.watch.system.common.result.Result;
import com.watch.system.model.form.ConfigForm;
import com.watch.system.model.query.CarConfigPageQuery;
import com.watch.system.model.query.CarUserPageQuery;
import com.watch.system.model.vo.CarConfigPageVO;
import com.watch.system.service.CarConfigService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 系统配置控制器
 *
 * @author gmli
 * @since 2024/02/26
 */
@Tag(name = "15.中车会系统参数配置接口")
@RestController
@RequestMapping("/api/car/config")
@RequiredArgsConstructor
public class CarConfigController {

    private final CarConfigService carConfigService;

    @Operation(summary = "系统配置分页列表")
    @GetMapping("/page")
    public PageResult<CarConfigPageVO> getConfigPage(
            @ParameterObject CarConfigPageQuery queryParams
    ) {
        IPage<CarConfigPageVO> result = carConfigService.getConfigPage(queryParams);
        return PageResult.success(result);
    }

    @Operation(summary = "修改配置")
    @PutMapping(value = "/saveConfig")
    public Result saveConfig(@RequestBody @Validated ConfigForm ConfigForm) {
        boolean result = carConfigService.saveConfig(ConfigForm.getConfigId(), ConfigForm);
        return Result.judge(result);
    }

    @Operation(summary = "删除配置")
    @DeleteMapping("/{ids}")
    public Result deleteConfig(@Parameter(description = "配置ID，多个以英文逗号(,)分割") @PathVariable String ids) {
        boolean result = carConfigService.deleteConfig(ids);
        return Result.judge(result);
    }
}
